.include "record-def.s"
.include "linux.s"

.section .data
.equ ST_ERROR_CODE, 16
.equ ST_ERROR_MSG, 24

.section .text
.globl error_exit
.type error_exit, @function
error_exit:
    push    %rbp
    mov     %rsp, %rbp

    # 写错误代码
    mov     ST_ERROR_CODE(%rbp), %rcx
    push    %rcx
    call    count_chars
    pop     %rcx
    mov     %rax, %rdx
    mov     $STDERR, %rbx
    mov     $SYS_WRITE, %rax
    int     $LINUX_SYSCALL

    # 写错误信息
    mov     ST_ERROR_MSG(%rbp), %rcx
    push    %rcx
    call    count_chars
    pop     %rcx
    mov     %rax, %rdx
    mov     $STDERR, %rbx
    mov     $SYS_WRITE, %rax
    int     $LINUX_SYSCALL

    push    $STDERR
    call    write_newline

    mov     $SYS_EXIT, %rax
    mov     $1, %rbx
    int     $LINUX_SYSCALL
